<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <form action="" class="layui-form" lay-filter="commentsForm">
        <input id="comments_id" name="comments_id" type="hidden">
        <div class="layui-form layuimini-form" lay-filter="vaccineForm">
            <div class="layui-form-item">
                <label class="layui-form-label required">评论的用户id</label>
                <div class="layui-input-block">
                    <input type="number" name="user_id" id="user_id" lay-verify="required" lay-reqtext="用户名不能为空"
                        placeholder="请输入评论人的名称" value="" class="layui-input" readonly>
                </div>
            </div>

            <!-- <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">评论内容</label>
                <div class="layui-input-block">
                    <textarea name="comments_content" id="comments_content" class="layui-textarea" lay-reqtext="内容不能为空"
                        placeholder="请输入内容" ></textarea>
                </div>
            </div> -->



            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">评论内容</label>
                <div class="layui-input-block">
                    <!-- <textarea name="comments_content" class="layui-textarea" placeholder="请输入新闻具体内容" readonly></textarea> -->
                    <textarea name="comments_content" id="comments_content" class="layui-textarea" placeholder="请输入新闻具体内容" ></textarea>
                    <!-- <textarea class="layui-textarea" name="comments_content" id="lay_content" style="display: none"
                        placeholder="请输入评论内容" readonly>
                    </textarea> -->
                </div>
            </div>



            <div class="layui-form-item">
                <label class="layui-form-label required">评论时间</label>
                <div class="layui-input-block">
                    <input type="text" name="comments_createtime" id="comments_createtime" lay-verify="required"
                        lay-reqtext="评论时间不能为空" placeholder="请输入评论时间" value="" class="layui-input" readonly>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新闻编号</label>
                <div class="layui-input-block">
                    <input type="number" name="news_id" id="news_id" lay-verify="required" lay-reqtext="新闻编号不能为空"
                        placeholder="请输入新闻编号" value="" class="layui-input" readonly>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </form>
    <script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'layedit'], function () {
            var form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate,
                layedit = layui.layedit
            $ = layui.$;
            laydate.render({
                elem: '#date'
            });

            //构建一个默认的编辑器
            var index = layedit.build('lay_content');


            //从localStorage 把数据取出来  赋值给表单项
            var jsonStr = localStorage.getItem("comments");
            var commentsObj = JSON.parse(jsonStr);
            // alert(commentsObj.comments_content)
            //给表单项赋值
            form.val("commentsForm", {
                comments_id: commentsObj.comments_id,
                user_id: commentsObj.user_id,
                comments_content: commentsObj.comments_content,
                comments_createtime: commentsObj.comments_createtime,
                news_id: commentsObj.news_id
            });

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                // var index = layer.alert(JSON.stringify(data.field), {
                //     title: '最终的提交信息'
                // }
                var index = layer.alert(JSON.stringify(data.field.comments_content), {
                    title: '最终的提交信息'
                } , function () {

                    // 关闭弹出层
                    layer.close(index);

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);

                });

                $.ajax({
                    url: "http://localhost:8080/admin/news/comments/edit",
                    data: data.field,
                    type: 'post',
                    success: function (data) {
                        if (data.code == 200) {
                            // parent.layer.msg("修改成功")
                            // layer.alert("修改成功")
                        }
                    },
                    error: function (data) {
                        console.log("bbb = " + data)
                        layer.alert("修改失败!")
                    }
                });

                return false;
            });
        });
    </script>
</body>

</html>